//
//  LCLogisticsViewController.m
//  EnterpriseCloud
//
//  Created by 东亨 on 2017/7/12.
//  Copyright © 2017年 lichao. All rights reserved.
//

#import "LCLogisticsViewController.h"
#import "LCDetailsViewController.h"
#import "LCConsultingCell.h"
#import "LCHeadView.h"
#import "ListModel.h"
static NSString *cellIdentifier = @"LCConsultingCell";
@interface LCLogisticsViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSInteger _page;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong,nonatomic)NSMutableDictionary  *dataDic;
@property (strong,nonatomic)NSMutableArray       *dataArray;

@end

@implementation LCLogisticsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setBarTitle:@"物业服务"];
    _dataDic = [[NSMutableDictionary alloc]initWithCapacity:0];
    _dataArray = [[NSMutableArray alloc]initWithCapacity:0];
    [self loadCustomeView];
}
- (void)loadCustomeView
{
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableFooterView = [[UIView alloc]init];
    [_tableView registerNib:[UINib nibWithNibName:@"LCConsultingCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
    _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{//下拉刷新
        _page = 1;
        [self loadData];
    }];
    _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{//上拉刷新
        [self loadData];
    }];
    [_tableView.mj_header beginRefreshing];
}
-(void)loadData
{
    if (_page == 1)
    {
        [_dataArray removeAllObjects];
    }
    [_dataDic setObject:@"6" forKey:@"column_id"];
    [_dataDic setObject:@"10" forKey:@"pageSize"];
    [_dataDic setObject:[NSString stringWithFormat:@"%ld",_page] forKey:@"pageNum"];
    [_dataDic setObject:@"property" forKey:@"type"];
    if (get_sp(@"company_id"))
    {
        [_dataDic setObject:get_sp(@"company_id") forKey:@"company_id"];
    }
    [MDataProvider getPropertyListWithBodyDic:_dataDic sucess:^(NSArray *array)
     {
         [_dataArray addObjectsFromArray:array];
         _page++;
         [_tableView reloadData];
         [_tableView.mj_header endRefreshing];
         [_tableView.mj_footer endRefreshing];
         if (array.count<10)
         {
             self.tableView.mj_footer.state = MJRefreshStateNoMoreData;
         }
         else
         {
             self.tableView.mj_footer.state = MJRefreshStateIdle;
         }
        
    } faile:^(NSString *str) {
        [_tableView.mj_header endRefreshing];
        [_tableView.mj_footer endRefreshing];
        [SVProgressHUD showErrorWithStatus:str];
    }];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    LCHeadView *view = [[LCHeadView alloc]initWithTitle:@"物业服务"];
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
#pragma mark -UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LCConsultingCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    ListModel *model = [_dataArray objectAtIndex:indexPath.row];
    cell.titlLbl.text = model.title;
    cell.paperLbl.text = model.summary;
    cell.timeLbl.text = model.published_date;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    LCDetailsViewController *vc = [[LCDetailsViewController alloc]init];
    ListModel *model = [_dataArray objectAtIndex:indexPath.row];
    vc.info_id = model.info_id;
    [self.navigationController pushViewController:vc animated:YES];
}
@end
